package dataInv

import (
	"context"
	inventory_pb "mxshop/api/inventory/v1"
	IInv "mxshop/app/mxshop_api/api/internal/data/inv"
	doInv "mxshop/app/mxshop_api/api/internal/domain/do/inv"
)

type inventory struct {
	ic inventory_pb.InventoryClient
}

func (i inventory) InvDetail(ctx context.Context, ID int64) (*doInv.InventoryDO, error) {
	var ret doInv.InventoryDO

	rsp, err := i.ic.InvDetail(ctx, &inventory_pb.GoodsInvInfo{GoodsId: ID})
	if err != nil {
		return nil, err
	}

	ret = doInv.InventoryDO{
		Goods:  rsp.GoodsId,
		Stocks: rsp.Num,
	}

	return &ret, nil
}

func newInventory(ic inventory_pb.InventoryClient) IInv.Inventory {
	return &inventory{ic: ic}
}
